package com.ywb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

    }


//    //注意MyMVCConfig是WebMvcAutoConfiguration的拓展配置，既然要拓展所以方法名字需要跟其方法名字相同
//    //否则无法生效
//    //因为mvc拓展配置中没有localeresolver所以我们要把它注册为bean
//    @Bean
//    public LocaleResolver localeResolver() {
//        return new MyLocaleResolver();
//    }
//
    //把刚刚创建的Interceptor加入到mvcconfig中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**") //对所有的网址添加拦截器
                .excludePathPatterns("/user/**","/css/**", "/js/**", "/images/**", "/fonts/**");
//              放行user登录界面和static样式资源;
    }

//    springbootWeb开启delete和put请求
    @Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter(){
        HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
        hiddenHttpMethodFilter.setMethodParam("_m");
        return hiddenHttpMethodFilter;
    }
}
